from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-20 14:05:05.986076
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 20, Jul, 2022
Time: 14:05:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.8632
Nobs: 723.000 HQIC: -50.2135
Log likelihood: 9088.76 FPE: 1.25003e-22
AIC: -50.4337 Det(Omega_mle): 1.10467e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299619 0.056986 5.258 0.000
L1.Burgenland 0.107160 0.037332 2.870 0.004
L1.Kärnten -0.106992 0.019798 -5.404 0.000
L1.Niederösterreich 0.209367 0.078231 2.676 0.007
L1.Oberösterreich 0.106250 0.076320 1.392 0.164
L1.Salzburg 0.253589 0.039946 6.348 0.000
L1.Steiermark 0.042721 0.052116 0.820 0.412
L1.Tirol 0.108306 0.042279 2.562 0.010
L1.Vorarlberg -0.063135 0.036488 -1.730 0.084
L1.Wien 0.048327 0.067485 0.716 0.474
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054802 0.119086 0.460 0.645
L1.Burgenland -0.031459 0.078015 -0.403 0.687
L1.Kärnten 0.046889 0.041373 1.133 0.257
L1.Niederösterreich -0.178890 0.163482 -1.094 0.274
L1.Oberösterreich 0.412623 0.159490 2.587 0.010
L1.Salzburg 0.288802 0.083476 3.460 0.001
L1.Steiermark 0.106786 0.108908 0.981 0.327
L1.Tirol 0.311910 0.088352 3.530 0.000
L1.Vorarlberg 0.026047 0.076250 0.342 0.733
L1.Wien -0.030359 0.141028 -0.215 0.830
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188283 0.029095 6.471 0.000
L1.Burgenland 0.089991 0.019060 4.721 0.000
L1.Kärnten -0.008856 0.010108 -0.876 0.381
L1.Niederösterreich 0.264119 0.039941 6.613 0.000
L1.Oberösterreich 0.137114 0.038966 3.519 0.000
L1.Salzburg 0.045984 0.020395 2.255 0.024
L1.Steiermark 0.020520 0.026608 0.771 0.441
L1.Tirol 0.092806 0.021586 4.299 0.000
L1.Vorarlberg 0.056492 0.018629 3.032 0.002
L1.Wien 0.114729 0.034455 3.330 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111397 0.029652 3.757 0.000
L1.Burgenland 0.045685 0.019426 2.352 0.019
L1.Kärnten -0.013813 0.010302 -1.341 0.180
L1.Niederösterreich 0.189991 0.040707 4.667 0.000
L1.Oberösterreich 0.300946 0.039713 7.578 0.000
L1.Salzburg 0.109353 0.020785 5.261 0.000
L1.Steiermark 0.104570 0.027118 3.856 0.000
L1.Tirol 0.105116 0.021999 4.778 0.000
L1.Vorarlberg 0.068184 0.018986 3.591 0.000
L1.Wien -0.022002 0.035116 -0.627 0.531
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130635 0.054040 2.417 0.016
L1.Burgenland -0.049861 0.035403 -1.408 0.159
L1.Kärnten -0.040788 0.018775 -2.172 0.030
L1.Niederösterreich 0.166400 0.074187 2.243 0.025
L1.Oberösterreich 0.140207 0.072375 1.937 0.053
L1.Salzburg 0.288831 0.037881 7.625 0.000
L1.Steiermark 0.036091 0.049422 0.730 0.465
L1.Tirol 0.163020 0.040094 4.066 0.000
L1.Vorarlberg 0.099331 0.034602 2.871 0.004
L1.Wien 0.068458 0.063997 1.070 0.285
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055667 0.042995 1.295 0.195
L1.Burgenland 0.039237 0.028167 1.393 0.164
L1.Kärnten 0.051403 0.014937 3.441 0.001
L1.Niederösterreich 0.218498 0.059024 3.702 0.000
L1.Oberösterreich 0.295572 0.057583 5.133 0.000
L1.Salzburg 0.043691 0.030139 1.450 0.147
L1.Steiermark 0.001182 0.039321 0.030 0.976
L1.Tirol 0.142319 0.031899 4.462 0.000
L1.Vorarlberg 0.072452 0.027530 2.632 0.008
L1.Wien 0.080830 0.050917 1.587 0.112
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175697 0.051374 3.420 0.001
L1.Burgenland -0.002858 0.033656 -0.085 0.932
L1.Kärnten -0.062446 0.017848 -3.499 0.000
L1.Niederösterreich -0.081441 0.070526 -1.155 0.248
L1.Oberösterreich 0.191221 0.068804 2.779 0.005
L1.Salzburg 0.057648 0.036012 1.601 0.109
L1.Steiermark 0.235751 0.046983 5.018 0.000
L1.Tirol 0.497867 0.038115 13.062 0.000
L1.Vorarlberg 0.044547 0.032894 1.354 0.176
L1.Wien -0.053516 0.060840 -0.880 0.379
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174324 0.058954 2.957 0.003
L1.Burgenland -0.007026 0.038622 -0.182 0.856
L1.Kärnten 0.066397 0.020482 3.242 0.001
L1.Niederösterreich 0.207390 0.080933 2.563 0.010
L1.Oberösterreich -0.075471 0.078956 -0.956 0.339
L1.Salzburg 0.207482 0.041325 5.021 0.000
L1.Steiermark 0.122993 0.053916 2.281 0.023
L1.Tirol 0.070215 0.043739 1.605 0.108
L1.Vorarlberg 0.116022 0.037748 3.074 0.002
L1.Wien 0.120126 0.069816 1.721 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.361673 0.033988 10.641 0.000
L1.Burgenland 0.007082 0.022266 0.318 0.750
L1.Kärnten -0.023914 0.011808 -2.025 0.043
L1.Niederösterreich 0.217772 0.046659 4.667 0.000
L1.Oberösterreich 0.199835 0.045519 4.390 0.000
L1.Salzburg 0.043039 0.023825 1.806 0.071
L1.Steiermark -0.014809 0.031083 -0.476 0.634
L1.Tirol 0.105229 0.025216 4.173 0.000
L1.Vorarlberg 0.070149 0.021762 3.223 0.001
L1.Wien 0.036047 0.040250 0.896 0.370
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040083 0.138388 0.191071 0.150591 0.117311 0.102711 0.061707 0.215825
Kärnten 0.040083 1.000000 -0.006596 0.132785 0.038959 0.094644 0.433811 -0.053549 0.097968
Niederösterreich 0.138388 -0.006596 1.000000 0.334825 0.140846 0.293713 0.095011 0.175325 0.313677
Oberösterreich 0.191071 0.132785 0.334825 1.000000 0.227781 0.324759 0.175152 0.163546 0.261508
Salzburg 0.150591 0.038959 0.140846 0.227781 1.000000 0.142045 0.111280 0.143486 0.123032
Steiermark 0.117311 0.094644 0.293713 0.324759 0.142045 1.000000 0.145698 0.136699 0.070827
Tirol 0.102711 0.433811 0.095011 0.175152 0.111280 0.145698 1.000000 0.110269 0.142131
Vorarlberg 0.061707 -0.053549 0.175325 0.163546 0.143486 0.136699 0.110269 1.000000 -0.002192
Wien 0.215825 0.097968 0.313677 0.261508 0.123032 0.070827 0.142131 -0.002192 1.000000